<?
    include "../common.php" ;
    $opt = $_POST['opt'] ; 
    $arr = [] ; 
    if( $opt == 'getList' ){
        $uid = $_POST['uid'] ;
        $sql = "SELECT p.pname,p.price,c.pnum,`pid`,c.id FROM shopcar AS c JOIN products AS p ON c.pid = p.id WHERE c.uid = {$uid}" ;
        $res = mysqli_query($link,$sql);
        while( $one = mysqli_fetch_assoc($res) ){
            $arr[] = $one ; 
        }
    }
    if( $opt == 'optData' ){
        $id = $_POST['id'] ;
        $num = $_POST['num'] ;
        $sql = "UPDATE `shopcar` SET pnum = {$num} WHERE id = {$id}" ;
        $res = mysqli_query($link,$sql);
        if( $res ){
            $arr['status'] = 1 ;
            $arr['info'] = '操作成功!' ; 
        } else {
            $arr['status'] = 0 ;
            $arr['info'] = '操作失败!' ;
        }
    }
    if( $opt == 'delData' ){
        $id = $_POST['id'] ;
        $sql = "DELETE FROM `shopcar` WHERE id = {$id}" ;
        $res = mysqli_query($link,$sql);
        if( $res ){
            $arr['status'] = 1 ;
            $arr['info'] = '操作成功!' ; 
        } else {
            $arr['status'] = 0 ;
            $arr['info'] = '操作失败!' ;
        }
    }
    echo json_encode($arr);
?>